Skip to content

Experimental: add starlarklibrary gazelle extension#410

Open
pcj wants to merge 17 commits intomasterfrom
stardoc
Open

Experimental: add starlarklibrary gazelle extension#410
pcj wants to merge 17 commits intomasterfrom
stardoc

Conversation

@pcj
Copy link
Copy Markdown
Member

@pcj pcj commented Nov 30, 2025

Experimental new gazelle extension for collecting the .bzl files of an external resource. Not proto related, it could be upstreamed to gazelle itself if useful.

pcj added 8 commits November 29, 2025 22:55
Lets MODULE.bazel point starlark_repository at a workspace-local path
instead of an http_archive. Useful when the source already lives on
disk — e.g. a git submodule — and we want to skip the network fetch
entirely. The bcr-frontend project hits this with ~449 overlay-bzl
modules that all derive from the same bazel-central-registry archive;
emitting one `.archive(urls=...)` per module trips GitHub's 429 rate
limit on cold caches.

Changes
- extensions/starlark_repository.bzl: new `local` tag class with attrs
  {name, path, build_directives, build_file_generation, languages,
  cfgs, imports, imports_out (default "imports.csv"), deleted_files,
  reresolve_known_proto_imports, importpath}. The extension impl maps
  user-facing `path` to the underlying `local_path` attr and dispatches
  to the same starlark_repository repo rule used by `.archive`.
- rules/proto/proto_repository.bzl: in `_proto_repository_impl`'s
  local_path branch, resolve workspace-relative paths against the main
  workspace root (via Label("@@//:MODULE.bazel").dirname) before
  passing them to ctx.watch_tree() and fetch_repo's --path arg. Bare
  strings were otherwise interpreted relative to the external repo's
  own dir, where the directory doesn't exist.
- rules/proto/proto_repository.bzl: in _generate_proto_repository_info,
  return empty string when imports_out is unset, so a future caller
  with no imports_out can't trip `exports_files([""])`.

Usage:

    starlark_repository = use_extension(
        "@build_stack_rules_proto//extensions:starlark_repository.bzl",
        "starlark_repository",
    )
    starlark_repository.local(
        name = "bzl.colordiff---1.0.22",
        path = "data/bazel-central-registry/modules/colordiff/1.0.22/overlay",
        build_directives = ["gazelle:starlarkrepository_root"],
        build_file_generation = "clean",
        languages = ["starlarkrepository"],
    )
    use_repo(starlark_repository, "bzl.colordiff---1.0.22")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant